<?php
include_once '../comic/WCAuthor.php';
include_once '../utils/WCDBLayer.php';
include_once '../conf/Conf.php';

//I am going to assume this is going to work...
$db = new WCDBLayer(Conf::$db_url,Conf::$db_user,Conf::$db_password);
$db->connect(Conf::$db);

$auth = new WCAuthor($db);

try{
	$auth->save();
}catch(WCException $e){	
	echo '<p class="error">',$e->getCode()+': ',$e->getMessage(),'</p>';
	echo $e->printHTMLTrace();
}
$auth->setAttribute(WCAuthor::$ATTR_AUTHOR_NAME,'author3');

try{
	$auth->save();
}catch(WCException $e){	
	echo '<p class="error">',$e->getCode()+': ',$e->getMessage(),'</p>';
	echo $e->printHTMLTrace();
}

$id = $auth->getId();
unset($auth);

$auth = new WCAuthor($db,$id);
$auth->dump();
$auth->setAttribute(WCAuthor::$ATTR_AUTHOR_DESCRIPTION,'AWESOME!!');
$auth->save();

unset($auth);

$auth = new WCAuthor($db,$id);
$auth->dump();

echo 'description set: '.$auth->isAttrSet(WCAuthor::$ATTR_AUTHOR_DESCRIPTION).'<br/>';
echo 'website set: '.$auth->isAttrSet(WCAuthor::$ATTR_AUTHOR_WEBPAGES).'<br/>';
echo 'does_not_exist set: '.$auth->isAttrSet('does_not_exist').'<br/>';

$auth->setAttribute('does_not_exist','if inserted go boom!!');


$auth->setAttribute(WCAuthor::$ATTR_AUTHOR_ROLE,"I'm ga-ga about (parenthesis) #signs and \\ slashes!!");
$auth->save();

unset($auth);

$auth = new WCAuthor($db,$id);
$auth->dump();

$auth2 = new WCAuthor($db,5);
$auth->addPartner($auth2);
echo array_pop($auth2->getPartnerIds());
?>
